function longestMountain(A: number[]) {
  const len = A.length
  let ans = 0
  let start = 0
  while (start < len) {
    let end = start
    if (end + 1 < len && A[end + 1] > A[end]) {
      while (end + 1 < len && A[end + 1] > A[end]) end += 1
      if (end + 1 < len && A[end] > A[end + 1]) {
        while (end + 1 < len && A[end] > A[end + 1]) end += 1
        ans = Math.max(ans, end - start + 1)
      }
    }
    start = Math.max(end, start + 1)
  }
  return ans
}

export { longestMountain }
